// Task ventilator in C++
// Binds PUSH socket to tcp://localhost:5557
// Sends batch of tasks to workers via that socket

#include <zmq.hpp>
#include <iostream>
#include <unistd.h>

int main() {
    zmq::context_t context(1);
    zmq::socket_t sender(context, ZMQ_PUSH);
    sender.bind("tcp://*:5557");

    std::cout << "Press Enter when the workers are ready: ";
    getchar();
    std::cout << "Sending tasks to workers...\n";

    int total_msec = 0;
    while (true) {
        int workload = /* generate workload */;
        total_msec += workload;

        zmq::message_t message(10);
        memcpy(message.data(), &workload, sizeof(int));
        sender.send(message);

        sleep(1); // Give 0MQ time to deliver
    }

    std::cout << "Total expected cost: " << total_msec << " msec\n";
    return 0;
}


import zmq

context = zmq.Context()
receiver = context.socket(zmq.PULL)
receiver.connect("tcp://localhost:5557")

while True:
    workload = receiver.recv_string()
    print(f"Received workload: {workload}")


import zmq
import time

context = zmq.Context()
sender = context.socket(zmq.PUSH)
sender.bind("tcp://*:5557")

while True:
    workload = /* generate workload */
    sender.send_string(str(workload))
    time.sleep(1)  # Give 0MQ time to deliver
